import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:music_app/modules/discover/index.dart';
import 'package:music_app/modules/my/index.dart';
import 'package:music_app/modules/note/index.dart';
import 'package:music_app/modules/recomment/index.dart';
import 'package:music_app/modules/roam/index.dart';
import 'main_tab_controller.dart';

class MainTabView extends GetView<MainTabController> {
  const MainTabView({super.key});

  final List<Widget> _pages = const [
    RecommentView(),
    DiscoverView(),
    RoamView(),
    NoteView(),
    MyView(),
  ];

  @override
  Widget build(BuildContext context) {
    return Obx(
      () => Scaffold(
        // IndexedStack用来保持切换导航也不会重新build
        body: Stack(
          children: [
            IndexedStack(
              index: controller.currentIndex.value,
              children: _pages,
            ),
          ],
        ),
        bottomNavigationBar: BottomNavigationBar(
          type: BottomNavigationBarType.fixed,
          currentIndex: controller.currentIndex.value,
          onTap: controller.changeTabIndex,
          items: const [
            BottomNavigationBarItem(
              icon: Icon(Icons.crisis_alert),
              label: '推荐',
            ),
            BottomNavigationBarItem(
              icon: Icon(Icons.smart_display),
              label: '视频',
            ),
            BottomNavigationBarItem(
              icon: Icon(Icons.music_note),
              label: '我的音乐',
            ),
            BottomNavigationBarItem(
              icon: Icon(Icons.radar),
              label: '发现',
            ),
          ],
        ),
      ),
    );
  }
}
